#include "Camera.h"
#include "Player.h"
#include "Game.h"
#include "..//SGD Wrappers//SGD_InputManager.h"
#include "GrappleHook.h"

Camera::Camera()
{
}

Camera::Camera(Player* player)
{
	m_pPlayer = player;
	m_ptCurrPos = player->GetPosition();
	m_fCameraOff = Game::GetInstance()->GetScreenWidth() * .25f;
	m_nCameraX = int(m_pPlayer->GetPosition().x - m_fCameraOff);
	m_nCameraY = int(m_pPlayer->GetPosition().y - Game::GetInstance()->GetScreenHeight() * .6f);
}

Camera::~Camera()
{

}

void Camera::Update(float dt)
{

	if (m_pPlayer->GetScale().width > 0.0f)
	{
		if (m_fCameraOff > Game::GetInstance()->GetScreenWidth() * .25f)
			m_fCameraOff -= 500 * dt;

		else
			m_fCameraOff = Game::GetInstance()->GetScreenWidth() * .25f;
	}
	else
	{
		if (m_fCameraOff < Game::GetInstance()->GetScreenWidth() * .75f)
			m_fCameraOff += 500 * dt;
		else
			m_fCameraOff = Game::GetInstance()->GetScreenWidth() * .75f;
	}

	m_nCameraX = int(m_pPlayer->GetPosition().x - m_fCameraOff);

	if (std::abs(m_pPlayer->GetPosition().y - m_ptCurrPos.y) > 5)
		m_nCameraY = int(m_pPlayer->GetPosition().y - Game::GetInstance()->GetScreenHeight() * .6f);

	m_ptCurrPos = m_pPlayer->GetPosition();

}

void Camera::CameraShake()
{
	m_nCameraX += rand() % 5 - 2;
	m_nCameraY += rand() % 5 - 2;
}